package text_2023_10_02;

import java.util.Stack;

/**
 * @author Vv
 * @version 1.0
 * @project coding_learn
 * @description
 * @date 2023/10/2 01:24:37
 */

class MySatck{
    public Stack<Integer> stackDate;
    public Stack<Integer> stackMin;
    public MySatck(){
        this.stackDate = new Stack<>();
        this.stackMin = new Stack<>();
    }
    public void push(Integer newNum){
        if(this.isEmpty()){
            stackMin.push(newNum);
        }
        stackMin.push(this.getMin() >= newNum ? newNum : this.getMin());
        stackDate.push(newNum);
    }
    public Integer pop(){
        if(this.stackMin.isEmpty()){
            throw new RuntimeException("Your Stack is Empty");
        }
        stackMin.pop();
        return stackMin.pop();
    }
    public Integer getMin(){
        if(this.stackMin.isEmpty()){
            throw new RuntimeException("Your Stack is Empty");
        }else{
            return stackMin.peek();
        }

    }
    public boolean isEmpty(){
        return stackMin.isEmpty() && stackDate.isEmpty();
    }
    public int size(){
        return stackDate.size();
    }
}
public class Demo1 {
}
